package com.example.demo.entity;

import com.example.demo.constant.Role;
import lombok.*;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

//@Data
// @Builder
// @AllArgsConstructor
@NoArgsConstructor
public class Users implements UserDetails {
    private Long id;
    private String username;
    private String password;
    private Integer enabled;
    private List<Role> roles;

     @Override
     public Collection<? extends GrantedAuthority> getAuthorities() {
         return new ArrayList<>();
//         return roles.stream()
////                 .map(role -> "ROLE_" + role.name())
//                 .map(role -> new SimpleGrantedAuthority("ROLE_" + role.name()))
//                 .toList();
     }

    public void setRoles(List<Role> roles) {
        this.roles = roles;
    }

    public List<Role> getRoles() {
         return new ArrayList<>();
     }

    @Override
    public String getUsername() {
        return username;
    }

    @Override
    public String getPassword() {
        return password;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return enabled != null && enabled == 1;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    //    public Integer getEnabledStatus() {
//        return enabled;
//    }
}

//package com.example.demo.entity;

